package regelinterpreter02;

public class Rule {
	private String name;
	private int type; //1=LiteralEqualsValue
	private Statement statement;    //zur Regel zugehörige Aussage
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getType() {
		return type;
	}
	public void setType(int type) {
		this.type = type;
	}
	public Statement getStatement() {
		return statement;
	}
	public void setStatement(Statement statement) {
		this.statement = statement;
	}
	
	public String startRule(){  //feuern der Regel, je nach Attributtyp
		String answer = "";
		switch(type){
			case 1: //1=StatementEqualsValue
					for(int i = 0; i < statement.getValue_string().size(); i++){
						if(statement.getChosenValue().equals(statement.getValue_string().get(i))){
							answer = statement.getDiagnosis().get(i);
						}
					}
					break;
			case 2: //2=StatementOnly
				
					//evtl. noch reinzubringen
				
					break;
			case 3: //3=StatementEqualsStatement
					if(statement.getValue_string().size() != statement.getExtStatement().getValue_string().size()){
						return "false";
					} else {
						for(int i = 0; i < statement.getValue_string().size(); i++){
							if(!(statement.getValue_string().get(i).equals(statement.getExtStatement().getValue_string().get(i)))){
								return "false";
							}
						}
					}
					if(!(statement.getChosenValue().equals(statement.getExtStatement().getChosenValue()))) return "false";
					if(statement.isMultiChoice() != statement.getExtStatement().isMultiChoice()) return "false"; 
					if(!(statement.getQuestion().equals(statement.getExtStatement().getQuestion()))) return "false";
					if(statement.getDiagnosis().size() != statement.getExtStatement().getDiagnosis().size()){
						return "false";
					} else {
						for(int i = 0; i < statement.getDiagnosis().size(); i++){
							if(!(statement.getDiagnosis().get(i).equals(statement.getExtStatement().getDiagnosis().get(i)))){
								return "false";
							}
						}
					}
					break;
			case 4: //4=StatementGreaterValue
					for(int i = 0; i < statement.getValue_string().size(); i++){
						if(Tools.StringToFloat(statement.getChosenValue()) > Tools.StringToFloat(statement.getValue_string().get(i))){
							answer = statement.getDiagnosis().get(0);
						}
					}				
					break;	
			case 5: //5=StatementLessValue
					for(int i = 0; i < statement.getValue_string().size(); i++){
						if(Tools.StringToFloat(statement.getChosenValue()) < Tools.StringToFloat(statement.getValue_string().get(i))){
							answer = statement.getDiagnosis().get(0);
						}
					}
					break;
			case 6: //6=StatementUnequalsValue
					for(int i = 0; i < statement.getValue_string().size(); i++){
						if(Tools.StringToFloat(statement.getChosenValue()) != Tools.StringToFloat(statement.getValue_string().get(i))){
							answer = statement.getDiagnosis().get(0);
						}
					}
					break;				
		}
		return answer;
	}
}
